package com.ruoyi.common.enums;

import java.io.Serializable;


public interface BaseString  extends Serializable {
    String getCode();
    String getDesc();
    BaseString valOf(String code);
    /**
     * 根据code获取枚举实例
     * 每个枚举类需要自己实现这个方法
     */
    static <E extends BaseString> E fromCode(Class<E> enumClass, String code) {
        if (code == null) {
            return null;
        }
        for (E e : enumClass.getEnumConstants()) {
            if (code.equals(e.getCode())) {
                return e;
            }
        }
        throw new IllegalArgumentException("未知的枚举编码: " + code + " for " + enumClass.getSimpleName());
    }


}
